{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "external-seeker",
   "metadata": {},
   "source": [
    "# 一、统计bash的各个label之间的边的关系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "noted-identification",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import argparse\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import networkx as nx\n",
    "\n",
    "\n",
    "def GraphDraw(Data, output=None):\n",
    "    G = to_networkx(Data)\n",
    "    H = G.to_undirected()\n",
    "    pos = nx.kamada_kawai_layout(G)\n",
    "    plt.figure(figsize=(19.20, 10.80))\n",
    "    nx.draw(G,\n",
    "            pos,\n",
    "            with_labels=True,\n",
    "            alpha=0.7,\n",
    "            node_color=[[.7, .7, .7]],\n",
    "            node_size=15,\n",
    "            width=0.3,\n",
    "            font_size=8,\n",
    "            arrows=False\n",
    "            )\n",
    "    if output != None:\n",
    "        plt.savefig(output)\n",
    "    plt.show()\n",
    "    plt.savefig(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "minute-boards",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['symbol.csv',\n",
       " 'function_calls.csv',\n",
       " 'transitive.csv',\n",
       " 'funct_glob_var.csv',\n",
       " 'include.csv']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "outedge = \"out_edge/cluster\"\n",
    "os.listdir(outedge)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "sunrise-perspective",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cluster_id</th>\n",
       "      <th>general</th>\n",
       "      <th>error_handling</th>\n",
       "      <th>job_control</th>\n",
       "      <th>libbuiltins</th>\n",
       "      <th>libglob</th>\n",
       "      <th>libintl</th>\n",
       "      <th>libhistory</th>\n",
       "      <th>libmalloc</th>\n",
       "      <th>libreadline</th>\n",
       "      <th>libsh</th>\n",
       "      <th>libtermcap</th>\n",
       "      <th>libtilde</th>\n",
       "      <th>signal_handling</th>\n",
       "      <th>support</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>general</td>\n",
       "      <td>1102</td>\n",
       "      <td>31</td>\n",
       "      <td>36</td>\n",
       "      <td>31</td>\n",
       "      <td>48</td>\n",
       "      <td>0</td>\n",
       "      <td>18</td>\n",
       "      <td>29</td>\n",
       "      <td>106</td>\n",
       "      <td>581</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>32</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>error_handling</td>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>job_control</td>\n",
       "      <td>43</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>22</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>libbuiltins</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>libglob</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>libintl</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>libhistory</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>libmalloc</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>libreadline</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>0</td>\n",
       "      <td>268</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>libsh</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>libtermcap</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>libtilde</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>signal_handling</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>support</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         cluster_id  general  error_handling  job_control  libbuiltins  \\\n",
       "0           general     1102              31           36           31   \n",
       "1    error_handling       36               1            1            0   \n",
       "2       job_control       43               1            2            1   \n",
       "3       libbuiltins       27               0            2            1   \n",
       "4           libglob       13               0            0            0   \n",
       "5           libintl        0               0            0            0   \n",
       "6        libhistory        6               0            0            0   \n",
       "7         libmalloc        0               0            0            0   \n",
       "8       libreadline       35               0            0            0   \n",
       "9             libsh        0               0            0            0   \n",
       "10       libtermcap        0               0            0            0   \n",
       "11         libtilde        5               0            0            1   \n",
       "12  signal_handling       40               1            2            0   \n",
       "13          support        0               0            0            0   \n",
       "\n",
       "    libglob  libintl  libhistory  libmalloc  libreadline  libsh  libtermcap  \\\n",
       "0        48        0          18         29          106    581           6   \n",
       "1         1        0           0          0            0     15           0   \n",
       "2         0        0           0          0            0     22           0   \n",
       "3         1        0           0          0            0      0           0   \n",
       "4         4        0           0          0            0      1           0   \n",
       "5         0        0           0          0            0      0           0   \n",
       "6         0        0           8          0           18      0           0   \n",
       "7         0        0           0          0            0      0           0   \n",
       "8         0        0          19          0          268      0           0   \n",
       "9         0        0           0          0            0      2           0   \n",
       "10        0        0           0          0            0      0           2   \n",
       "11        0        0           0          0            0      1           0   \n",
       "12        1        0           0          0            0     15           0   \n",
       "13        0        0           0          0            0      0           0   \n",
       "\n",
       "    libtilde  signal_handling  support  \n",
       "0          5               32        0  \n",
       "1          0                1        0  \n",
       "2          1                2        0  \n",
       "3          0                1        0  \n",
       "4          0                0        0  \n",
       "5          0                0        0  \n",
       "6          0                0        0  \n",
       "7          0                0        0  \n",
       "8          0                0        0  \n",
       "9          0                0        0  \n",
       "10         0                0        0  \n",
       "11         1                0        0  \n",
       "12         0                1        0  \n",
       "13         0                0        0  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "includefile = os.path.join(outedge,'include.csv')\n",
    "import pandas as pd\n",
    "data = pd.read_csv(includefile)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "pressing-action",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
